package classLoader;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;


/**
 * 在类LoaderSample2中可以创建处于另一命名空间的类LoaderSample3中的对象并可以访问其公共成员age
 * @author Administrator
 *
 */
public class LoaderSample2 {
	public static void main(String[] args) {
	try {
		URL[] us = {new URL("http:///")};
		ClassLoader loader = new URLClassLoader(us);
		Class c = loader.loadClass("classLoader.sub.LoaderSample3");
		Object o = c.newInstance();
		Field f = c.getField("age");
		int age = f.getInt(o);
		System.out.println("age is " + age);
		Method m = c.getMethod("getAge", Integer.class,String.class);
		m.invoke(o, 11, "jovi");
		}catch(Exception e) {
			e.printStackTrace();
		}
	}
}
